// UDPTransport.h: interface for the CUDPTransport class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_UDPTRANSPORT_H__7C37438A_5AB8_4B2B_9B98_43F5BA2FFD77__INCLUDED_)
#define AFX_UDPTRANSPORT_H__7C37438A_5AB8_4B2B_9B98_43F5BA2FFD77__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "mysocket.h"
#include "Transport.h"
#include "Fifo.h"

class CTransaction; //yb added 20100203
class UDPPacket
{
public:
    UDPPacket():
            content(NULL),
            contLen(0),
            usProduceTime(0),
            usRequestTime(0),
            pTransaction(NULL),
            stateMachine_Next(-1)
    {
        memset(&addr, 0, sizeof(addr));
        memset(transactionID, 0, sizeof(transactionID));
    }
    virtual ~UDPPacket()
   {
        if(content) delete [] content;
   }
    char* content;
    int contLen;
    sockaddr_in addr;

    int64 usProduceTime;
    int64 usRequestTime;
    CTransaction *pTransaction;
    int    stateMachine_Next;
    char transactionID[128];
};

class CUDPTransport:public CTransport
{
public:
	bool IsOK(){return m_s != INVALID_SOCKET;};
	int Send(sockaddr_in &addr,char *pbuf,int len);
	CUDPTransport(CSIPStack* pStack, const mystring& ip, uint16 port);
	virtual ~CUDPTransport();
	virtual void DoSend();
	virtual void DoRecv();
    
    void DoParseSIP();
	virtual bool SendMsg(CSIPMessage &Msg);
	virtual CSIPMessage *RecvMsg();
	int	SetSocketRcvBufSize(int inNewSize);
	int	SetSocketBufSize(int inNewSize);

#ifdef IPV6_SUPPORT
	int Sendbuf(mystring & ip_address, uint16 port, char * pbuf, int len);
#endif
private:
	SOCKET	m_s;

//yb added{
private:
    static void *SIPParseProc(void *argc);
    static void *SendProc(void *argc);
    bool SendMsg_Directly(const char* buf, int bufLen, sockaddr_in& addr);

    CFifo<UDPPacket>  m_udpPacketFifo;
    pthread_t m_hSIPParserThread;
    CFifo<UDPPacket>  m_udpPacketFifo_Send;
    pthread_t m_hSendThread;
//yb added}
	
};

#endif // !defined(AFX_UDPTRANSPORT_H__7C37438A_5AB8_4B2B_9B98_43F5BA2FFD77__INCLUDED_)
